import Vue from 'vue';
import App from './App.vue';
import createRouter from './router';
import createStore from './store';
import { sync } from 'vuex-router-sync';

import axios from 'axios';

export default () => {
	const router = createRouter();
	const store = createStore();

	sync(store, router);

	axios.interceptors.request.use(function (config) {
		return config;
	}, function (error) {
		return Promise.reject(error);
	});

	// 响应拦截器
	axios.interceptors.response.use(function (response) {
		store.dispatch('changeNetworkStatus', true);
		return response;
	}, function (error) {
		store.dispatch('changeNetworkStatus', false);
		return Promise.reject(error);
	});

	const app = new Vue({
		router,
		store,
		render: (h) => h(App)
	});

	return { app, router, store };
};
